import { apiGetFiles, apiRemoveFile } from '@/api/AttachmentManagement/index'
import { apiGetAllCates, apiCatesModify } from '@/api/CategoriesManagement/index'

export default {
  methods: {
    getFiles(userId, params) {
      apiGetFiles(userId, params).then(res => {
        // console.log('apiGetFiles', res);
        const data = res.data || []
        this.pagination.total = res.totalRecords || 0
        this.tableData = Object.freeze(data)
        this.tableLoading = false
      })
        .catch(err => {
          console.log(err);
          this.tableData = []
          this.pagination.total = 0
          this.tableLoading = false
        })
    },

    getAllCates(params) {
      apiGetAllCates(params).then(res => {
        // console.log('apiGetAllCates', res);
        this.attachmentTypes = res || []
        // this.formData.tags = res[0].className
      })
        .catch(err => {
          console.log(err);
          this.attachmentTypes = []
        })
    },

    removeFile(fileId) {
      apiRemoveFile(fileId).then(res => {
        // console.log('apiRemoveFile', res);
        if (res && res.message) {
          this.$message.error(res.message)
        }

      }).catch(err => {
        console.log(err);
        this.$message.success('删除成功')
        this.handleFormSubmit();
      })
    },

    modifyCates(id, data) {
      apiCatesModify(id, data).then(res => {
        // console.log('modifyCates', res);
        if (res && res.code === 200) {
          this.$message.success(res.message)
          this.handleFormSubmit();
        } else {
          this.$message.error('修改失败')
        }
      }).catch(err => {
        // console.log(err);
        this.$message.error(err)
      })
    },
  }
}